#include <fstream>
#include <QApplication>

#include "DGVSurfacePlotVTK.h"

const int Size = 256;

///Prototypes
Array<imageType,2> createGaussian();

int main(int argc, char *argv[])
{
    QApplication app(argc,argv);
    DGVSurfacePlotVTK MainWindow;
    Array<imageType,2> gaussian(Size,Size);
    ofstream outFile("gauss.csv");

    ///Generate 2D Gaussian Function
    gaussian = createGaussian();

    ///Output to CSV file
    for (int j = 0; j < Size; j++)
    {
        for (int k = 0; k < Size; k ++)
            outFile << gaussian(j,k) << ", ";
        outFile << endl;
    }
    outFile.close();

    ///Make and show Surface plot
    MainWindow.setData(gaussian); ///Assign the data
    MainWindow.generatePlot(); ///Generate mesh
    MainWindow.generateAxes(); ///Generate Dynamic axes

    MainWindow.show(); ///Show result

    return app.exec();
}

Array<imageType,2> createGaussian()
{
    ///Gaussian Parameters
    double amplitude = 100.0, stdDev_x = Size/2, stdDev_y = Size/2, x0 = Size/2, y0 = Size/2;
    double variance_x = stdDev_x*stdDev_x, variance_y = stdDev_y*stdDev_y;

    ///Index generators/placeholder
    ///These automatically run through the x, y values of the array
    firstIndex x;
    secondIndex y;

    Array<imageType,2> gauss(Size,Size);

    gauss = amplitude*exp( -( (x-x0)*(x-x0)/variance_x + (y-y0)*(y-y0)/variance_y ) );

    return gauss;
}
